package com.lu.pojo.network;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author luzhenfang
 * @date 2020 05 16
 * @description 网络基础:IP
 */
public class TestIp {
    public static void main(String[] args) {
        try {
            // 查询本机地址
            InetAddress localhost = InetAddress.getByName("localhost");
            InetAddress host = InetAddress.getLocalHost();
            System.out.println(host);
            // 查询名字地址
            InetAddress addrName = InetAddress.getByName("wwww.baidu.com");
            System.out.println(localhost);
            System.out.println(addrName);
            // 获取规范地址
            System.out.println(addrName.getCanonicalHostName());
            // 获取自己电脑名称
            System.out.println(localhost.getHostName());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    } }
